package dS.ProjectGPS.LeicaOWI;

import javax.microedition.lcdui.*;
import java.util.Date;

public class FormOwiNXT extends Form implements FormOwi {

  OWIAgent owiAgent = null;

  TextField utcTime = new TextField("UTC Time", "", 50, TextField.ANY);
  TextField utcDate = new TextField("UTC Date", "", 50, TextField.ANY);
  TextField latency = new TextField("Latency", "", 50, TextField.ANY);
  TextField confidence = new TextField("Confidence Indicator", "", 50,
                                       TextField.ANY);
  TextField solutionType = new TextField("Solution Type", "", 50, TextField.ANY);
  ChoiceGroup positionFormat = new ChoiceGroup("Position Format",
                                               ChoiceGroup.POPUP);
  ChoiceGroup datumId = new ChoiceGroup("Datum ID", ChoiceGroup.POPUP);
  StringItem note1 = new StringItem("", "If Geodetic Position Format",
                                    StringItem.PLAIN);
  TextField latitude = new TextField("Latitude", "", 50, TextField.ANY);
  TextField longitude = new TextField("Longitude", "", 50, TextField.ANY);
  StringItem stringItem1 = new StringItem("", "If Grid Position Format",
                                          StringItem.PLAIN);
  TextField gridNorthing = new TextField("Grid Northing", "", 50, TextField.ANY);
  TextField gridEasting = new TextField("Grid Easting", "", 50, TextField.ANY);
  TextField height = new TextField("Height", "", 50, TextField.ANY);
  TextField qualityLat = new TextField("Quality Latitude", "", 50,
                                       TextField.ANY);
  TextField qualityLon = new TextField("Quality Longitude", "", 50,
                                       TextField.ANY);
  TextField qualityHeight = new TextField("Quality Height", "", 50,
                                          TextField.ANY);

  public FormOwiNXT(OWIAgent o) {
    super("");

    owiAgent = o;

    try {
      ndsInit();
    }
    catch (Exception ex) {
    }
  }

  public void ndsInit() throws Exception {
    append(utcTime);
    append(utcDate);
    append(latency);
    append(confidence);
    append(solutionType);
    append(positionFormat);
    append(datumId);
    positionFormat.append("Geodetic", null);
    positionFormat.append("Grid", null);
    datumId.append("WGS84", null);
    datumId.append("Local", null);
    append(note1);
    append(latitude);
    append(longitude);
    append(stringItem1);
    append(gridEasting);
    append(gridNorthing);
    append(height);
    append(qualityLat);
    append(qualityLon);
    append(qualityHeight);
  }

  public void update() {
    owiAgent.query(OWI.qsNXT("" + positionFormat.getSelectedIndex(),
                   "0.05", "10"));

    utcTime.setString(OWI.nxtUtcTime);
    utcDate.setString(OWI.nxtUtcDate);
    latency.setString(OWI.nxtLatency);
    confidence.setString(OWI.nxtConfidence);
    solutionType.setString(OWI.nxtSolutionType);
    positionFormat.setSelectedIndex(OWI.nxtPositionFlag, true);
    datumId.setSelectedIndex(OWI.nxtDatumId, true);
    latitude.setString(OWI.nxtLatitude);
    longitude.setString(OWI.nxtLongitude);
    qualityHeight.setString(OWI.nxtQualHeight);
    qualityLat.setString(OWI.nxtQualLat);
    qualityLon.setString(OWI.nxtQualLong);
    height.setString(OWI.nxtQualHeight);
  }

  public void save() {
    // N/A
  }

}
